/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.bytedance.scene.ui.bottomnavigation;

import ohos.agp.render.Canvas;

/**
 * BadgeItem
 *
 * @param <T>
 * @since 2021-06-16
 */
public abstract class BadgeItem<T extends BadgeItem<T>> {
    private BottomNavigationBar bottomNavigationBar;

    private boolean mIsHidden = false;

    /**
     * getBottomNavigationBar
     *
     * @return bottomNavigationBar
     */
    public BottomNavigationBar getBottomNavigationBar() {
        return bottomNavigationBar;
    }

    /**
     * setBottomNavigationBar
     *
     * @param bottomNavigationBar bottomNavigationBar
     */
    public void setBottomNavigationBar(BottomNavigationBar bottomNavigationBar) {
        this.bottomNavigationBar = bottomNavigationBar;
    }

    /**
     * toggle
     *
     * @return T
     */
    public T toggle() {
        if (mIsHidden) {
            return show();
        } else {
            return hide();
        }
    }

    /**
     * show
     *
     * @return T
     */
    public T show() {
        mIsHidden = false;
        if (bottomNavigationBar != null) {
            bottomNavigationBar.invalidate();
        }
        return getSubInstance();
    }

    /**
     * hide
     *
     * @return T
     */
    public T hide() {
        mIsHidden = true;
        if (bottomNavigationBar != null) {
            bottomNavigationBar.invalidate();
        }
        return getSubInstance();
    }

    /**
     * isHidden
     *
     * @return mIsHidden
     */
    public boolean isHidden() {
        return mIsHidden;
    }

    /**
     * setOffset
     *
     * @param moffsetX moffsetX
     * @param moffsetY moffsetY
     * @return T
     */
    public T setOffset(float moffsetX, float moffsetY) {
        return getSubInstance();
    }

    /**
     * clearOffset
     *
     * @return T
     */
    public T clearOffset() {
        return getSubInstance();
    }

    /**
     * isHideOnSelect
     *
     * @return isHideOnSelect
     */
    public boolean isHideOnSelect() {
        return false;
    }

    abstract T getSubInstance();

    abstract void drawToCanvas(
            Canvas canvas,
            float centerX,
            float centerY,
            float defaultOffsetX,
            float defaultOffsetY);

    abstract void drawToCanvas1(
            int size,
            int padding);
}
